// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 .
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : gjm_scb.v
// Author        : 
// Created On    : 2022-08-25 15:55
// Last Modified : 
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

`ifndef __GJM_SCB_SV__
`define __GJM_SCB_SV__

class gjm_scb extends uvm_scoreboard;
   gjm_transaction  expect_q[$];
   uvm_blocking_get_port #(gjm_transaction)  exp_port;
   uvm_blocking_get_port #(gjm_transaction)  act_port;
   `uvm_component_utils(gjm_scb)

   extern function new(string name, uvm_component parent = null);
   extern virtual function void build_phase(uvm_phase phase);
   extern virtual task main_phase(uvm_phase phase);
endclass 

function gjm_scb::new(string name, uvm_component parent = null);
   super.new(name, parent);
endfunction: new

function void gjm_scb::build_phase(uvm_phase phase);
   super.build_phase(phase);
   exp_port = new("exp_port", this);
   act_port = new("act_port", this);
endfunction: build_phase

task gjm_scb::main_phase(uvm_phase phase);
    gjm_transaction  get_expect,  get_actual, tmp_tran;
    bit result;
    super.main_phase(phase);
    fork 
        while (1) begin
           exp_port.get(get_expect);
           expect_q.push_back(get_expect);
        end
        while (1) begin
            act_port.get(get_actual);
            if(expect_q.size() > 0) begin
                tmp_tran = expect_q.pop_front();
                result = get_actual.compare(tmp_tran);
                if(result) begin 
                   `uvm_info("gjm_scb", "Compare SUCCESSFULLY", UVM_LOW);
                end
                else begin
                    `uvm_error("gjm_scb", "Compare FAILED");
                    $display("RM:");
                    tmp_tran.print();
                    $display("RTL:");
                    get_actual.print();
                end
            end
            else begin
                `uvm_error("gjm_scb", "Received from DUT, while Expect Queue is empty");
                get_actual.print();
            end 
        end
    join_none
endtask: main_phase

`endif
